<?xml version="1.0" encoding="UTF-8"?>
<shuie order="50" active="true">
  <title><![CDATA[Print(Any)WebPart]]></title>
  <contexts />
  <javascript minify="true">
    <code>
      <![CDATA[
if (typeof jQuery != "undefined")
  $(document).ready(function(){
    // Find all web parts by their TD and loop through web parts
    $("td[id^='MSOZoneCell_WebPart']").each(function(){
      // Append an image with onClick event
      $(this).find("h3 nobr").append(
        "<span id='print" + $(this).attr("id") + "' style='padding-left:20px;'>" +
        "  <a href='#' onClick='printWebPart(" + '"' + $(this).attr("id") + '"' + "); return false;'>" +
        "    <img src='/_layouts/images/nws16.gif' border='0' alt='Printer this web part' />" +
        "  </a>" +
        "</span>"
      );
      $(this).find("td.ms-toolbar[width='99%']").append(
        "<span id='print" + $(this).attr("id") + "' style='padding-left:20px;'>"+
        "  <a href='#' onClick='printWebPart(" + '"' + $(this).attr("id") + '"' + "); return false;'>"+
        "    <img src='/_layouts/images/printerfriendly.gif' border='0' alt='printer friendly' />"+
        "  </a>"+
        "</span>"
      );
    });
  });

function printWebPart(tagid){
  if (!tagid)
    return;
  
  $("#print" + tagid).css("visibility","hidden");
  
  var webPartHtml = $("#" + tagid + " .ms-listviewtable") ?
    $("#" + tagid + " .ms-listviewtable").html() :
    $("#" + tagid).html();
  
  // Build html for print page
  var html =
    "<HTML><HEAD>" +
    $("head").html() +
    "</HEAD><BODY>" +
    webPartHtml +
    "</BODY></HTML>";
  
  $("#print" + tagid).css("visibility","visible");
      
  // Open new window
  var printWP = window.open("","printWebPart");
  printWP.document.open();
  
  // Insert content
  printWP.document.write(html);
  printWP.document.close();
     
  // Open print dialog
  printWP.print();
}
      ]]>
    </code>
  </javascript>
</shuie>
